﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;

namespace Query2Object
{
    class Configs
    {
        public static SortedDictionary<string, string> connections;
        public static SortedDictionary<string, qDbType> dbtypes;
        public static List<string> Keys;
        /// <summary>
        /// Load data from config section
        /// 从配置文件里获取配置数据
        /// </summary>
        static Configs()
        {
            Keys = new List<string>();
            connections = new SortedDictionary<string, string>();
            dbtypes = new SortedDictionary<string, qDbType>();
            DataBaseSection sec = (DataBaseSection)ConfigurationManager.GetSection("Query2Object/DataBase");
            foreach (ConnectionItem item in sec.Items)
            {
                if (!connections.ContainsKey(item.name))
                {
                    Keys.Add(item.name);
                    connections.Add(item.name, item.connectionstring);
                    dbtypes.Add(item.name, (qDbType)Enum.Parse(typeof(qDbType), item.dbtype));
                }
            }
        }
    }
    /// <summary>
    /// Type of Database
    /// 数据库类型，限制在配置文件里面配置的输入
    /// </summary>
    public enum qDbType
    {
        SqlServer2005,
        SqlServer2000,
        Access,
        CommonOdbc,
        Mysql,
        Oracle
    }
}
